//
//  NSObject+ClearNull.m
//  MovingLoaniOS
//
//  Created by RAIN on 2018/9/6.
//  Copyright © 2018 - 2019 GWMFC. All rights reserved.
//

#import "NSObject+ClearNull.h"

@implementation NSObject (ClearNull)

- (nonnull NSString *)rg_withoutNull {
    NSArray<NSString *> *clearStrings = @[@"NaN", @"<null>", @"(null)"];
    return [self rg_clearNilAndOtherStrings:clearStrings];
}

- (nonnull NSString *)rg_clearNilAndOtherStrings:(nullable NSArray <NSString *> *)otherStrings {
    if (self == nil || [self isKindOfClass:[NSNull class]]) {
        return @"";
    } else {
        NSString *string = [NSString stringWithFormat:@"%@", self];
        if (otherStrings == nil) {
            return string;
        } else {
            BOOL condition = NO;
            for (NSString *otherString in otherStrings) {
                condition = condition || [string isEqualToString:otherString];
            }
            if (condition) {
                return @"";
            } else {
                return string;
            }
        }
    }
}

@end
